import {
  Controller,
  Get,
  Post,
  Body,
  Put,
  Delete,
  Query,
} from '@nestjs/common';
import { BlogService } from './blog.service';
import { CreateBlogDto } from './dto/create-blog.dto';
import { API, BlogAPI } from "../../types";

@Controller('blog')
export class BlogController {
  constructor(private readonly blogService: BlogService) {}

  /**
   * @description 创建博客
   * @author rogi
   * @Query {string} title 标题
   * @Query {string} content 内容
   * @Query {string} tagIds 分类ids
   * @Query {string} head 头像
   * @Query {string} banner 是否为banner
   * @Query {string} id 博客id
   */
  @Post('/create')
  create(@Body() createBlogDto: CreateBlogDto) {
    return this.blogService.create(createBlogDto);
  }

  /**
   * @description 获取博客列表
   * @author rogi
   * @Query {number} current 页码
   * @Query {number} pageSize 分页大小
   */
  @Get('/findAll')
  findAll(@Query() query: API.paging & BlogAPI.blogTableSearch) {
    return this.blogService.findAll(query);
  }

  /**
   * @description 获取博客详情
   * @author rogi
   * @Query {string} id 博客id
   */
  @Get('/getInfo')
  findOne(@Query('id') id: string) {
    return this.blogService.findOne(id);
  }

  /**
   * @description 更新博客banner
   * @author rogi
   * @Query {string} id 博客id
   * @Query {1 | 0} banner banner状态
   */
  @Put('/updateBanner')
  updateBanner(@Body() body: { id: string; banner: 1 | 0 }) {
    return this.blogService.updateBanner(body);
  }

  /**
   * @description 更新侧边栏
   * @author rogi
   * @Query {string} id 博客id
   * @Query {1 | 0} sideRecommend 首页侧边状态
   */
  @Put('/updateSideRecommend')
  updateSideRecommend(@Body() body: { id: string; sideRecommend: 1 | 0 }) {
    return this.blogService.updateSideRecommend(body);
  }

  /**
   * @description 删除博客
   * @author rogi
   * @Body {string} id 博客id
   */
  @Delete('/delete')
  remove(@Body('id') id: string) {
    return this.blogService.remove(id);
  }
}
